[TinyOWS-dev] pg_get_serial_sequence VS column_default for Pkey

Serge Dikiy serge at gisfiber.com
Mon Feb 20 09:15:06 EST 2012


I think it looks better:
https://bitbucket.org/sdikiy/tinyows/changeset/9e2ffdf2adf5

Now, as a Pkey, you can use any type for which PostgreSQL is able to
generate a unique value.

Like:
CREATE TABLE foo.fooo
(
uu_id uuid NOT NULL DEFAULT uuid_generate_v4(),
the_geom geometry,
CONSTRAINT fooo_pkey PRIMARY KEY (uu_id),
etc...
)

On 2/17/12, Serge Dikiy <serge at gisfiber.com> wrote:
> Hi,
>
> What do you think the change "pg_get_serial_sequence" ->
> "column_default" for Pkey?
> Like this:
>
> ================================
>
> diff -r 42ee60f4c797 ows/ows_psql.c
> --- a/ows/ows_psql.c	Fri Feb 17 14:03:53 2012 +0200
> +++ b/ows/ows_psql.c	Fri Feb 17 15:16:00 2012 +0200
> @@ -423,9 +423,9 @@
>       */
>       if (ln->layer->storage->pkey_sequence) {
>           sql_id = buffer_init();
> -         buffer_add_str(sql_id, "SELECT nextval('");
> +         buffer_add_str(sql_id, "SELECT ");
>           buffer_copy(sql_id, ln->layer->storage->pkey_sequence);
> -         buffer_add_str(sql_id, "');");
> +         buffer_add_str(sql_id, ";");
>           res = ows_psql_exec(o, sql_id->buf);
>           buffer_free(sql_id);
>
> diff -r 42ee60f4c797 ows/ows_storage.c
> --- a/ows/ows_storage.c	Fri Feb 17 14:03:53 2012 +0200
> +++ b/ows/ows_storage.c	Fri Feb 17 15:16:00 2012 +0200
> @@ -234,14 +234,14 @@
>          buffer_empty(sql);
>          PQclear(res);
>
> -        /* Now try to find a sequence related to this Pkey */
> -        buffer_add_str(sql, "SELECT pg_get_serial_sequence('");
> +        /* Now try to find a DEFAULT value related to this Pkey */
> +        buffer_add_str(sql, "SELECT column_default FROM
> information_schema.columns WHERE table_schema = '");
>          buffer_copy(sql, l->storage->schema);
> -        buffer_add_str(sql, ".\"");
> +        buffer_add_str(sql, "' AND table_name = '");
>          buffer_copy(sql, l->storage->table);
> -	buffer_add_str(sql, "\"', '");
> +        buffer_add_str(sql, "' AND column_name = '");
>          buffer_copy(sql, l->storage->pkey);
> -	buffer_add_str(sql, "');");
> +        buffer_add_str(sql, "';");
>
>          res = ows_psql_exec(o, sql->buf);
>          if (PQresultStatus(res) != PGRES_TUPLES_OK) {
>
> ================================
>
> Regards,
> Serge Dikiy
>


More information about the TinyOWS-dev mailing list