Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-05

Inserting enum type into Postgresql

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I need to insert a value into a custom type column in a PostgreSql database.

The type was created using this:

create type doc_type as enum('pdf', 'rtf', 'html', 'doc', 'docx', 'xls',
'xlsx', 'txt');

To insert a field into a table with one column of that type, I use:

var
   lQuery: TSqlQuery;
begin
   ...
   lQuery.Sql.Text := 'insert into documents(document_name,
document_type) values(:name, :type)';
   lQuery.ParamByName('type').AsString := 'txt';
   ...

I get "Primary Error: column "document_type" is of type doc_type but expression is of type text". How can I cast this?.

Regards,

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé
"Leonardo M. Ram?" wrote 22 lines
Hi, I need to insert a value into a custom type column in a PostgreSql database. The type was created using this: create type doc_type as enum('pdf', 'rtf', 'html', 'doc', 'docx', 'xls', 'xlsx', 'txt'); To insert a field into a table with one column of that type, I use: var lQuery: TSqlQuery; begin ... lQuery.Sql.Text := 'insert into documents(document_name, document_type) values(:name, :type)'; lQuery.ParamByName('type').AsString := 'txt'; ... I get "Primary Error: column "document_type" is of type doc_type but expression is of type text". How can I cast this?.

I would think
insert into documents(document_name, document_type) values(:name, (:type)::doc_type )'; ?

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt

El 15/05/15 a las 12:26, Michael Van Canneyt escibi?:

Show quoted text 35 lines
On Fri, 15 May 2015, "Leonardo M. Ram?" wrote: > Hi, I need to insert a value into a custom type column in a PostgreSql > database. > > The type was created using this: > > create type doc_type as enum('pdf', 'rtf', 'html', 'doc', 'docx', > 'xls', 'xlsx', 'txt'); > > To insert a field into a table with one column of that type, I use: > > var > lQuery: TSqlQuery; > > begin > ... > lQuery.Sql.Text := 'insert into documents(document_name, > document_type) values(:name, :type)'; > lQuery.ParamByName('type').AsString := 'txt'; > ... > > I get "Primary Error: column "document_type" is of type doc_type but > expression is of type text". How can I cast this?. I would think insert into documents(document_name, document_type) values(:name, (:type)::doc_type )'; ? Michael.

Yes, that was the solution.

Leonardo.

Reply by email