Benjamin Pineau bpineau at elma.fr
Sat Jan 23 08:40:39 PST 2010
I'm very new to slony and may well be wrong, 
but this rings a bell since I've just looked at this part of slony's source.

On Tue, Jan 19, 2010 at 10:26:06PM +1300, Maxim Boguk wrote:
> When i trying run this with slonik i got error:
> postgres at shalyapin:~/dba/plus1/slonik_scripts$ slonik ./execute_script.slonik
> DDL script consisting of 3 SQL statements
> DDL Statement 0: (0,1026) [CREATE OR REPLACE FUNCTION
> percent_int(bigint, bigint) RETURNS numeric AS$body$ OR REPLACE
> FUNCTION percent_int(bigint, bigint) RETURNS numeric AS
> DECLARECE FUNCTION percent_int(bigint, bigint) RETURNS numeric AS
>           percent numeric(10,2);(bigint, bigint) RETURNS numeric AS
>     BEGIN   percent numeric(10,2);(bigint, bigint) RETURNS numeric AS

This looks like something you may get when feeding slonik with an sql
script containing CRLF end of lines.
Does running "sed -i -e 's/\r//g' ../sql/update.sql" improve things ?

Ie. in src/slonik/slonik.c, in replace_token() function we have this,
which seems buggy :

  for (i = o = 0; i < numlines; i++, o++)
  {
        /* just copy pointer if NULL or no change needed */
	if (!lines[i] || (strncmp((const char *)lines + i, token, toklen)))
	{
		if (lines[i] == 0x0d)           /* ||(lines[i] == 0x0a)) */
			break;

Maybe the intent was to trim CR from statements, but this actually
truncate strings, and let them overflow since "o" is used later to
null-terminate the string. Commenting those two lines would avoid
problems. Or if we really want to remove \r :

		if (lines[i] == 0x0d)           /* ||(lines[i] == 0x0a)) */ {
			o--; continue;
		}



More information about the Slony1-general mailing list